<?php
namespace Home\Controller;

use Think\Controller;

class IndexController extends HomeController
{
    public function __construct()
    {
        parent::__construct();



        //底部菜单设置
        $menus = C("MENUS");
        $menus[0] = array(
            'href'      =>  '/',
            'li_class'  =>  'padding-l margin-r',
            'src'       =>  C('TMPL_PARSE_STRING')['__IMG__'].'/menu-11.png',
            'p_class'   =>  'color-menu',
            'text'      =>  '首页'
        );
        C("MENUS",$menus);
    }

    //首页
    public function index()
    {
        //获取分类数据
        $Category   =   D("Category");
        $categorys   =   $Category->getTree();
//        getDepth($categorys,0,'child','depth');
//        $categorys = tree_to_list($categorys,'child');
        $this->assign('categorys',$categorys);
//        trace($categorys);



        $this->display();
    }

    public function test(){
        $a = rand(1,10);
        echo $a;
    }
    //分类页面
    public function cate(){
        //获取分类数据
        $Category   =   D("Category");
        $categorys   =   $Category->getTree();
//        getDepth($categorys,0,'child','depth');
//        $categorys = tree_to_list($categorys,'child');
        $this->assign('categorys',$categorys);
        trace($categorys);

        $this->display();
    }
    //商品列表
    public function lists(){
        $params = I('get.',0);
        $Goods   =   D("Goods");
        $goodss   =   $Goods->getGoods($params,$page=false);
        $show     =   $Goods->getShow();


//        dump($goodss);
//        dump(array_order($arrUsers,'age','desc'));

        if('asc' == $params['order']){
            $order = 'desc';
        }else{
            $order = 'asc';
        }
        $this->assign('order',$order);
        $sort = $params['sort']?$params['sort']:'sales';
        $this->assign('sort',$sort);




        $this->assign('category_id',$params['category_id']);
        $this->assign('goodss',$goodss);
        $this->assign('show',$show);
        $this->display();
    }

    //商品详情
    public function detail(){
        $id = I('goods',0);
        $Goods = D("Goods");
        $info = $Goods->getDetail($id);
        $info['images']  =   get_item_imgs($info['multimage'],0,'path');
        $info['content'] = html_entity_decode($info['content']);
        trace($info,'info');
        $this->assign('info',$info);

        $this->display();
    }
    public function kefu(){
        $url = urldecode(C("KEFU"));
        redirect($url);
    }
    public function more($position){
        $this->assign("position",$position);
        $this->display();
    }
    public function article($id){
        $Article = D("Article");
        $info = $Article->getDetail($id);
        trace($info,'info');
        $this->assign("info",$info);
        $this->display();
    }
}
